/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RuleInterence;

import Common.Constant;
import DataSource.Data;
import DataSource.DataEntry;
import Logger.ILog;
import Logger.LogManager;
import java.util.Vector;

/**
 *
 * @author Tuan
 */
public class HeartStrokeRule extends HealthRuleAbs{

    private Rule hypotensionRule;
    private Rule healthyRule;
    private Vector lstRecord;    
    private static final ILog logger = LogManager.GetLogger(HeartStrokeRule.class.getName());
    
    public HeartStrokeRule(DataEntry dataEntry, Rule hypotensionRule, Rule healthyRule){
        super(dataEntry);
        this.hypotensionRule = hypotensionRule;
        this.healthyRule = healthyRule;
        this.lstRecord = new Vector();
        this.symptom = "Heart Stroke";
    }
    
    public DiagnosticResult checkSymptom(Data data) {
        DiagnosticResult result = new DiagnosticResult(symptom, data);
        this.lstRecord.addElement(data);
        boolean isHighTemp = true;
        int recordCount = this.lstRecord.size() > Constant.PROLONG_RECORD_COUNT ? Constant.PROLONG_RECORD_COUNT : this.lstRecord.size();
        for(int i = recordCount - 1; i >= 0; i--){
            Data record = (Data) this.lstRecord.elementAt(i);
            if(record.getTemperature() >= Constant.HIGH_TEMPERATURE){
                isHighTemp &= true;
            } else {
                isHighTemp &= false;
            }
        }
        //String log ="HB => " + data.getHeartBeat() + " MHB => " + this.maxHeartBeat + " isHypo => " + (hypotensionRule.checkSymptom(data) != null ? "true" : "false") + " isHealthy => " + healthyRule.checkSymptom(data); 
        //logger.info(log);
        return isHighTemp && data.getHeartBeat() > this.maxHeartBeat && data.getSystolic() < Constant.HYPERTENSION_MIN_SBP_STAGE1 && data.getDiastolic() < Constant.HYPERTENSION_MAX_DBP_STAGE1
                ? result : null;
    }
    
}
